package com.dslcode.cloud.provider.order.service;

import com.dslcode.cloud.common.dto.goods.GoodsBuyDTO;
import com.dslcode.cloud.common.model.order.Order;
import com.dslcode.cloud.common.model.order.OrderGoods;
import com.dslcode.cloud.provider.order.mapper.OrderGoodsMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by dongsilin on 2017/9/27.
 */
@Slf4j
@Service
public class OrderGoodsService {

    @Autowired
    private OrderGoodsMapper orderGoodsMapper;

    @Transactional
    public OrderGoods save(GoodsBuyDTO buyGoods, Order order) {
        OrderGoods orderGoods = new OrderGoods(order.getId(), buyGoods.getId(), buyGoods.getName(), buyGoods.getPrice(), buyGoods.getBuyNum(), buyGoods.getImage(), buyGoods.getPrice(), order.getBuyerId());
        this.orderGoodsMapper.save(orderGoods);
        return orderGoods;
    }

}
